﻿using System;
using System.Linq;
using SD.LLBLGen.Pro.ORMSupportClasses;

using CARMSBusiness;
using CARMSBusiness.InterFace;
using CARMSData.HelperClasses;

namespace CARMS.Admin
{
    public partial class EventBulkDelete : PageBase
    {
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                 
                txtStartDate_CalendarExtender.Format = ApplicationConfiguration.DateFormat;
                txtEndDate_CalendarExtender.Format = ApplicationConfiguration.DateFormat;
       
            }
        }
         

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            var condition = new PredicateExpression();
            DateTime? dateBegin = null;
            DateTime? dateEnd = null;
            if (!string.IsNullOrEmpty(txtStartDate.Text.Trim()))
            {
                dateBegin = DateTime.Parse(txtStartDate.Text, ApplicationConfiguration.DateTimeFormatInfo);
               
            }
            if (!string.IsNullOrEmpty(txtEndDate.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtEndDate.Text, ApplicationConfiguration.DateTimeFormatInfo);
             
            }
            if (dateBegin.HasValue || dateEnd.HasValue)
            {
                condition.Add(LogFields.LogTime >= dateBegin);
            }
          
            int count = LogBusiness.BulkDelete(condition);
            Success(count + " events records deleted");
            CloseWindow(count > 0);
        }
    }
}
